<?php
namespace Common\Models;
use Common\BaseModel;
class Withdrawals extends BaseModel
{
	public $res;
	public $expire;
    public function initialize()
    {
        parent::initialize();
        $this->setSource('f_withdrawals');
    }

    public function get_list($params){
        $page = intval($params['page']);
        $size = intval($params['page_size']);
        if ($page > 0) {
            $page = ($page - 1) * $size;
        }
        $conditions="user_id={$params['user_id']}";
        $get_list = $this->find(array(
            'conditions'=>$conditions,
            'order'=>'created_at desc',
            'limit'=>$size,
            'offset'=>$page,
        ))->toarray();
        return $get_list;
    }


    public function withdrawalList($param){
        $list = $this::find(array(
            "user_id =$param[user_id]",
        ));
        return $list;
    }

    public function save_withdraw($params){
	    $result = $this::save($params);
	    //var_dump($this::getmessages());die();
	    if($result){
	        return true;
        }else{
	        return false;
        }
    }
		public function withdraw_list(){
			$condition=['conditions'=>'status=2',
			'litmit'=>20
		];
			return $this->find($condition);
		}
	//用户提现的钱，1,2,8
	public function get_withdrawaled($user_id){
		$condition['conditions']="user_id = $user_id and  status in (1,2,8)";
		$condition['columns']="sum(money) as c";
		$res=$this->findFirst($condition);
		if($res == false){
		return 0;
		}
		return doubleval($res->c);
	}


	/*
	 * 已提现的钱
	 */
	public function get_withdrawal_all($user_id){
        $condition="user_id = {$user_id} and  status=8";
	    $res = $this->SUM(
	        array(
                $condition,
                "column" => "money",
            )
        );
	    if($res){
            return $res.'';
        }else{
	        return '0.00';
        }

    }

}
